define(["jquery","bbcare",
    "scprit/followup/app/prematureOvarianFailure/prematureOvarianFailureDetail.servers.js",
    "scprit/followup/app/prematureOvarianFailure/prematureOvarianFailureDetail.ui.js",],function($,$bb,$servers,$ui){
    var event = {};
    event.init = function(){
        /*
        * 历史列表点击事件
        * */
        $("#history").on("click","li",function(){
            $(this).addClass("checked").siblings().removeClass("checked");
            var inParams = {
                "userId":$(this).attr("userId"),
                "createTime":$(this).html(),
                "evaluationType": "GLE;LES;OSI;DGLE"
            };
            var getQuesInfoCallback = function(data){
                if(data.success){
                    var combine = {},res2={};
                    var score = {};
                    for(var i = 0;i<data.data.length;i++){
                        if(data.data[i].type == "LES"){//生活事件量表：
                            var result2 = JSON.parse(data.data[i].result);
                            res2 = $.extend({},data.data[i],result2);
                        }else{
                            combine = $.extend({},data.data[i],combine);
                            score[data.data[i].type] = JSON.parse(data.data[i].answerResult);
                            if(data.data[i].type == "OSI"){//职业压力紧张的评估计算结果
                                var result3 = JSON.parse(data.data[i].result);
                                combine = $.extend({},result3,combine);
                            }
                        }
                    }
                    var mark = {},ques = {};
                    if(score['DGLE']){
                        if(score['DGLE']["mark"] || score['GLE']["mark"]){
                            if(score['DGLE']["mark"] && score['GLE']["mark"]){
                                mark = $.extend({},score['DGLE']["mark"],score['GLE']["mark"]);
                            }else if(score['DGLE']["mark"] && !score['GLE']["mark"]){
                                mark = $.extend({},score['DGLE']["mark"]);
                            }else{
                                mark = $.extend({},score['GLE']["mark"]);
                            }
                            ques = $.extend({},score['DGLE']["ques"],score['GLE']["ques"]);
                        }
                        score['GLE']["mark"] = mark;
                        score['GLE']["ques"] = ques;
                        delete score['DGLE'];
                    }
                    combine.answer = JSON.stringify(score);
                    $ui.lesInit({
                        "id":"#lifeEvent",
                        "data":res2
                    });
                    $ui.surveyResultInit({
                        "id":"#womenHeathy",
                        "data":combine
                    });

                    /*
                    * 查看详情：
                    * */
                    $(".wrap_left").on("click",".toDetail",function(){
                        var params = {
                            "userId":$(this).attr("userId"),
                            "type":$(this).attr("type"),
                            "userName":$(this).attr("userName"),
                            "phoneNo":$(this).attr("tel"),
                            "gender":$(this).attr("gender"),
                            "score":$(this).attr("score"),
                            "testTime":$(this).attr("testTime")
                        };
                        if($(this).attr("type") == "LES"){//生活事件量表
                            if(!$(this).attr("userId")){
                                $bb.toastShow("无该项问卷的记录",1500);
                                return
                            }
                            $bb.openPage("lifeEventScale",params);
                        }else if($(this).attr("type") == "GLE"){
                            $bb.openPage("womenHealthQuestionnaire",params);
                        }else{
                            if(!$(this).attr("userId")){
                                $bb.toastShow("无该项问卷的记录",1500);
                                return
                            }
                            $bb.openPage("surveyOfWomenHealth",params);//妇女健康
                        }
                    });
                }
            };
            $servers.getQuesInfo(inParams,getQuesInfoCallback);
        });

        $("#history li").eq(0).click();

        $(".item-title").find(".toDetail[type='laboratory']").click(function(){
            $bb.toastShow("该功能暂未对接",1500);
        });
    };
    return event;
});